package com.atguigu.flink.chapter10;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.runtime.state.storage.JobManagerCheckpointStorage;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

public class KafkaConsumeUpsertKafka {
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 4000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);
        env.enableCheckpointing(3000);
        env.getCheckpointConfig().setCheckpointStorage(new JobManagerCheckpointStorage());

        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
        // 通过 ddl 的方式创建连接器表
        tEnv.executeSql("create table sensor(" +
                " id string, " +
                " vc_sum int " +
                ")with(" +
                "  'connector' = 'kafka', " +
                "  'topic' = 's2_upsert', " +
                "  'properties.bootstrap.servers' = 'hadoop102:9092', " +
                "  'properties.group.id' = 'def', " +
                "  'scan.startup.mode' = 'earliest-offset', " +
                "  'format' = 'json' " +
                ")");

        tEnv.sqlQuery("select * from sensor").execute().print();

    }
}


//public class KafkaConsumeUpsertKafka {
//    public static void main(String[] args) throws Exception {
//        Configuration conf = new Configuration();
//        conf.setInteger("rest.port",2000);
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
//        env.setParallelism(1);
//        env.enableCheckpointing(3000);
//        env.getCheckpointConfig().setCheckpointStorage(new JobManagerCheckpointStorage());
//
//        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
//        //通过ddl的方式创建连接器
//        tEnv.executeSql("create table sensor(" +
//                "id string," +
//                "ts bigint," +
//                "vc int" +
//                ") with(" +
//                "  'connector' = 'kafka', " +
//                "  'topic' = 's2_upsert', " +
//                "  'properties.bootstrap.servers' = 'hadoop162:9092', " +
//                "  'properties.group.id' = 'abc', " +
//                "  'scan.startup.mode' = 'earliest-offset', " +
//                "  'format' = 'json' " +
//                ")");
//        tEnv.sqlQuery("select * from sensor").execute().print();
//    }
//}


//public class KafkaConsumeUpsertKafka {
//    public static void main(String[] args) throws Exception {
//        Configuration conf = new Configuration();
//        conf.setInteger("rest.port",2000);
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
//        env.setParallelism(1);
//        env.enableCheckpointing(3000);
//        env.getCheckpointConfig().setCheckpointStorage(new JobManagerCheckpointStorage());
//
//        //通过ddl的方式创建连接器
//        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
//        tEnv.executeSql("create table sensor(" +
//                "id string," +
//                "ts bigint," +
//                "vc int" +
//                ") with(" +
//                "  'connector' = 'kafka', " +
//                "  'topic' = 's2_upsert', " +
//                "  'properties.bootstrap.servers' = 'hadoop162:9092', " +
//                "  'properties.group.id' = 'abc', " +
//                "  'scan.startup.mode' = 'earliest-offset', " +
//                "  'format' = 'json' " +
//                ")");
//        tEnv.sqlQuery("select * from sensor").execute().print();
//    }
//}